package cn.doitedu.demos;

import com.google.common.hash.BloomFilter;
import com.google.common.hash.Funnels;

import java.nio.charset.Charset;

public class BloomFilterJava {
    public static void main(String[] args) {


        // 创建布隆过滤器
        BloomFilter<CharSequence> filter  = BloomFilter.create(Funnels.stringFunnel(Charset.defaultCharset()), 10000000, 0.0001);

        // 插入存量元素
        filter.put("a");
        filter.put("b");
        filter.put("c");
        filter.put("d");
        filter.put("e");


        // 判断某元素是否存在于存量集合中
        boolean bool1 = filter.mightContain("e");
        boolean bool2 = filter.mightContain("c");
        boolean bool3 = filter.mightContain("x");


        System.out.println(bool1);
        System.out.println(bool2);
        System.out.println(bool3);



    }
}
